#!/usr/bin/env python3

import codecs
import json
import http.client,urllib.parse,urllib.error
import time

class do_get_aminer_data(object):
    def __init__(self,name,university_name):
        self.name = name
        self.university_name = university_name
    def do_connect(self):
        params = urllib.parse.urlencode({
            'name': self.name,
            'aff': self.university_name
        })
        conn = http.client.HTTPSConnection('api.aminer.org')
        conn.request("GET", "/api/kit/gender/api/ch?%s"%params)
        response = conn.getresponse()

        if response.status == 200:

            data = str(response.read(),encoding = "utf-8")
            conn.close()
            data_json = json.loads(data)

            return data_json,response.status
        else:
            time.sleep(10)
            conn.close()
            return {},response.status
